package com.mandao.concurrency.interviewset.pooldemo;

/**
 * Description
 *      使用join实现线程的顺序执行
 * @author woniu
 * @date 2019/6/18 20:17
 */
public class ThreadTest {
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()->{
            System.out.println("t1------>");
        });

        Thread t2 = new Thread(()->{
            System.out.println("------>t2");
        });

        Thread t3 = new Thread(()->{
            System.out.println("t3------>");
        });

        //[0]主线程在执行
        t1.start();
        //[1]主线程调用了t1.join()  join是同步方法加了synchronized  分析源码 main线程调用了t1的wait()
        t1.join();
        //[2]主线程调用了t1.join() 主线程挂起  只有当t1执行完释放资源  main线程才会被唤醒
        t2.start();
        //[3]主线程再次被挂起
        t2.join();
        //[4]主线程调用
        t3.start();

    }
}
